package com.erp.framework.controller.form;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.erp.framework.SimpleConstants;

public abstract class SimpleBaseForm extends ActionForm implements Serializable, SimpleConstants {

	protected String selectedLang = "";
	public String getSelectedLang() { return selectedLang; }
	public void setSelectedLang(String selectedLang) { this.selectedLang = selectedLang; }
	
    private final FormCommonTemplate template = new FormCommonTemplate();

    protected String pageEvent = "";
    protected String pageMode = "";
    protected String pageEventSrc = "";
    protected String gotoURL = "";
    protected String moduleName = "";

    public SimpleBaseForm() {
    }

    public String getPageEvent() {
        return pageEvent;
    }

    public String getPageEventSrc() {
        return pageEventSrc;
    }

    public String getPageMode() {
        return pageMode;
    }

    public String getGotoURL() {
        return gotoURL;
    }

    public void setPageEvent(String pageEvent) {
        this.pageEvent = pageEvent;
    }

    public void setPageEventSrc(String pageEventSrc) {
        this.pageEventSrc = pageEventSrc;
    }

    public void setPageMode(String pageMode) {
        this.pageMode = pageMode;
    }

    public void setGotoURL(String gotoURL) {
        this.gotoURL = gotoURL;
    }

    /** **** validate ******** */

    // NOT intended to be overridden by subclasses
    public final void validate(ActionErrors errors) {
        coreValidate(errors);
        otherValidate(errors);        
    }

    // To be overridden by UserForm ONLY
    protected void coreValidate(ActionErrors errors) {
        baseCoreValidate(errors);
    }

    // NOT intended to be overridden by subclasses
    protected final void baseCoreValidate(ActionErrors errors) {
        // Put essential statements here
    }

    // To be overridden by subclasses other than UserForm
    protected void otherValidate(ActionErrors errors){}

    public void moreValidate(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

    }

    public void validateSearch(ActionErrors errors) {
        validate(errors);
    }
    
    public void moreValidateSearch(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

    }
    
    // NOT intended to be overridden by subclasses
    public final void reset(ActionMapping mapping, HttpServletRequest request) {
        pageEvent = "";
        pageEventSrc = "";
        gotoURL = "";

        coreReset(mapping, request);
        otherReset(mapping, request);
    }

    // To be overridden by UserForm ONLY
    protected void coreReset(ActionMapping mapping, HttpServletRequest request) {
        baseCoreReset(mapping, request);
    }

    // NOT intended to be overridden by subclasses
    protected final void baseCoreReset(ActionMapping mapping, HttpServletRequest request) {
        // Put essential statements here
    }

    // To be overridden by subclasses other than UserForm
    protected void otherReset(ActionMapping mapping, HttpServletRequest request){}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

    public FormCommonTemplate getTemplate() {
        return template;
    }

}
